﻿using System;
using System.Data;
using System.Configuration;
using System.ComponentModel;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace ERPWebDemos.Code
{
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:Controlgroup runat=server></{0}:Controlgroup>")]
    public class Controlgroup : CompositeControl, INamingContainer
    {
        #region 声明要显示的控件
        public Controltest ct1;
        public Controltest ct2;
        #endregion
        #region 构造方法
        public Controlgroup()
            : base()
        {

        }
        #endregion

        #region 显示方法
        //撰写
        protected override void CreateChildControls()
        {
            this.ct1 = new Controltest();
            this.ct2 = new Controltest();
            this.ct1.ID = "ct01";
            this.ct2.ID = "ct02";
            this.ct1.Visible = false;
            this.ct2.Visible = false;
            this.ct1.Visible = true ;
            this.ct2.Visible = true;
            Controls.Clear();
            this.Controls.Add(this.ct1);
            this.Controls.Add(this.ct2);
            ChildControlsCreated = true;


        }
        //布局
        protected override void Render(HtmlTextWriter writer)
        {
            EnsureChildControls();

            AddAttributesToRender(writer);

            writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding,
                "1", false);

            writer.RenderBeginTag(HtmlTextWriterTag.Table);
            writer.RenderBeginTag(HtmlTextWriterTag.Tr);
            writer.RenderBeginTag(HtmlTextWriterTag.Td);

            ct1.RenderControl(writer);

            writer.RenderEndTag();  // Td
            writer.RenderEndTag();  // Tr
            writer.RenderBeginTag(HtmlTextWriterTag.Tr);
            writer.RenderBeginTag(HtmlTextWriterTag.Td);



            ct2.RenderControl(writer);

            writer.RenderEndTag();  // Td
            writer.RenderEndTag();  // Tr
            writer.RenderEndTag();  // Table
        }
        #endregion

        #region 外部方法

         
        public string Text()
        {
            return ct1.Text + "_" + ct2.Text;
        }
        #endregion
    }
}
